import table from '@/components/dt/table/render.js'
import dateOpt from '@/biz/option/date.js'
import Opt from '@/components/dt/info/Opt.js'
import dt from '@dt/dt'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        field: 'batchName',
        minWidth: 200,
        title: '批次名',
        header: {
          filter: {
            title: '批次名',
            key: 'batchName',
            placeholder: '请输入批次名',
            input: {},
          },
        }
      },
      {
        title: '日期',
        field: 'createTime',
        minWidth: 180,
        header: {
          filter: dateOpt.range({
            title: '日期',
            startKey: 'startTime',
            endKey: 'endTime',
            disabled: (date) => {
              return date.valueOf() > new Date().getTime()
            },
            check: (val) => {
              if (_this.$tool.dateDiff(val.startTime, val
                  .endTime).Y >= 2) {
                // 日期最大跨度两年
                _this.$Message.warning('日期跨度至多两年。')
              }
              return !(_this.$tool.dateDiff(val.startTime, val
                .endTime).Y >= 2)
            }
          }),
        },
      },

      {
        title: '导入线索数',
        field: 'totalNum',
        minWidth: 150,
      },
      {
        title: '成功导入线索数',
        field: 'successNum',
        minWidth: 150,
      },
      {
        title: '未分配数量',
        field: 'unallocatedNum',
        minWidth: 150,
      },
      {
        title: '分配中数量',
        field: 'allocatingNum',
        minWidth: 150,
      },
      {
        title: '已分配数量',
        field: 'allocatedNum',
        minWidth: 150,
      },
      {
        title: '线索客户数',
        field: 'clueNum',
        minWidth: 150,
      },
      {
        title: '导入状态',
        field: 'status',
        minWidth: 150,
        cell: {
          value: (item) => {
            return item.status == 1 ? '已完成' : item.status == 2 ? '导入失败' : '导入中'
          },
          text: {}
        },
      },
      {
        title: '操作人',
        field: 'userName',
        minWidth: 150,
      },
      {
        title: '操作',
        fixed: 'right',
        minWidth: 240,
        align: 'center',
        slots: {
          default: (params, h) => {
            let obj = params.row
            let btns = []
            btns.push({
              title: obj.status == '1' ? '查看' : '',
              event: 'checkFun',
              data: obj
            })
            btns.push({
              title: _this.unlocking('0213030200') && (obj.status == '2' || (obj
                  .status == '1' && obj.unallocatedNum == obj.successNum)) ? '删除' :
                '',
              event: 'delFun',
              data: obj
            })
            btns.push({
              title: _this.unlocking('0213030300') && obj.unallocatedNum ? '分配' : '',
              event: 'allotFun',
              data: obj
            })
            btns.push({
              title: _this.unlocking('0213030400') && obj.status == '1' ? '下载导入记录' :
                '',
              event: 'downloadFun',
              data: obj
            })
            return table.cell.btns(_this, h, btns)
          }
        }
      }
    ]
  }

}

export default Column